import axios from 'axios'
import config from './config'
import ENV from './apiList'
import vuex from './vuex'
//
function API() {
    //获取已授权列表
    this.Boot = function(param, url, diyurl) {
        config.data.data = param.data;
        switch (ENV.APILIST[url]) {
            case undefined:
                //
                break;
            case 'diy':
                return axios.post(diyurl, {}, config);
                break;
            default:
                return axios.post(ENV.APILIST[url], {}, config);
                break;
        }
    };
  this.get = function(param) {
            // config.data.data = param.data;
            return axios.get(config.baseURL + ENV.APILIST[param.api], param.data, config);
        };
        //添加授权
  this.post = function(param) {
          this.token();
          config.params.page = 1;
          if(param.page){

            config.params.page = param.page;
            return axios.post(ENV.APILIST[param.api], param.data, config);
          }
            return axios.post(ENV.APILIST[param.api], param.data, config);
    };
  this.token = function () {
    let token = vuex.moduleClientRoute.state.token;
    // console.log(vuex);
    if (token) {
      config.params.Authorization = token
    }
  };
  this.reqSuccess= function(obj, msg) {
        obj.$message({
            message: msg,
            fuck: 'feifei',
            type: 'success'
        });
    };
  this.reqFail= function(obj, msg) {
        obj.$message({
            message: msg,
            type: 'success'
        });
    }
}
export default API;
